Filter Data

Multiple Filters that Dynamically Update Each Other

Description
This customization shows how to implement multiple filters that dynamically update each other.
Variables
First Filter Control
Select a filter control whose items are populated from a number or character type field in the database
Second Filter Control
Select another filter control whose items are populated from a number or character type field in the database
Parent Table Control
Select the parent table control where the filter exist.
Table
Select the database table associated with the Parent Table Control
First Filter Field
Select the field associated with first filter
Second Filter Field
Select the field associated with second filter
Applies to
TableControl class
Code
 
''' 
''' This method sets the AutoPostBack property of the field that triggers a change.
''' 
Protected Sub MultipleDropdown_myInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init

        ' AutoPostBack sets or retrieves a value that indicates whether or not the control
        ' posts back to the server each time a user interacts with the control. 
        ' if change in second filter updates the first then set
        ' AutoPostback of the second filter to true and implement 
        ${First Filter Control}.AutoPostBack = True
        ${Second Filter Control}.AutoPostBack = True
        
        
    AddHandler ${First Filter Control}.SelectedIndexChanged, AddressOf ${First Filter Control}_SelectedIndexChanged
    ${Second Filter Control}.Enabled = False

End Sub


  
 
Applies to
TableControl class
Code
 
''' 
''' This method handles the SelectedIndexChanged for ${First Filter Control} 
''' 
Protected Overrides Sub ${First Filter Control}_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    ${Second Filter Control}.Enabled = True

    ' ${Second Filter Control} Filter will display 100 items.
    ' You can set the number of items displayed in the filter.
    Me.Populate${Second Filter Control}DropDown(100)
            
End Sub  
 
Applies to
TableControl class
Code
 
''' 
''' Override this method to filter the  ${Second Filter Control}DropDownList
''' based on the value selected for the ${First Filter Control}DropDownList
''' 
Protected Sub Populate${Second Filter Control}DropDown(ByVal maxItems As Integer)

    ' Set up the WHERE clause.
    ' Create the WHERE clause to filter the second filter based on
    ' the selected value of first filter.
    Dim wc As WhereClause = New WhereClause
    Dim selectedValue As String = ${First Filter Control}.SelectedValue  
    Dim selectedText As String = ${First Filter Control}.SelectedItem.Text
    wc.iAND(${${Table}ClassName}.${First Filter Field}, BaseFilter.ComparisonOperator.EqualsTo, selectedValue)

    ' Clear the contents of second filter.
    Me.${Second Filter Control}.Items.Clear()
    
    ' Add "Please Select" string to the second filter.
    Me.${Second Filter Control}.Items.Insert(0, New ListItem(Page.GetResourceValue("Txt:PleaseSelect", "${Application Name}"), "--PLEASE_SELECT--"))                      
    
    If (BaseClasses.Utils.StringUtils.InvariantUCase(selectedText).Equals(BaseClasses.Utils.StringUtils.InvariantUCase(Page.GetResourceValue("Txt:PleaseSelect", "${Application Name}"))))
        ' if "Please Select" string is selected for first filter,
        ' then do not continue populating the second filter.
        Return    
    End If
    
    ' Get the records using the created where clause.    
    Dim itemValue As ${${Table}RecordClassName}
    For Each itemValue In ${${Table}ClassName}.GetRecords(wc, Nothing, 0, maxItems)
            
        If (itemValue.${Second Filter Field}Specified)
            ' In each record, obtain the value of second dropdown field if value exists,
            ' create an item for it and add it to the list.
            Dim cvalue As String = itemValue.${Second Filter Field}.ToString()
            Dim fvalue As String = itemValue.Format(${${Table}ClassName}.${Second Filter Field})
            Dim item As ListItem = New ListItem(fvalue, cvalue)
            If (Not Me.${Second Filter Control}.Items.Contains(item))
                Me.${Second Filter Control}.Items.Add(item)        
            End If      
        End If
    Next                    

    ' Select "Please Select" string in the second filter.
    Me.${Second Filter Control}.SelectedIndex = 0
End Sub   
 

Terms of Service Privacy Statement